package com.zhangfei.function;

import java.util.function.Supplier;

public class SupplierTest {

    private static String newString(Supplier<String> supplier) {
        return supplier.get();
    }


    private static Integer getMax(Supplier<Integer> supplier) {
        return supplier.get();
    }


    public static void main(String[] args) {
        //lambda表达式
        String str1 = newString(() -> {
            return "当归";
        });
        System.out.println("lambda表达式:" + str1);


        //lambda表达式简化
        String str2 = newString(() ->
                "当归"
        );
        System.out.println("lambda表达式简化:" + str2);

        //获取数组中最大值
        int[] arr = {1, 2, 44, 55, 77, 556645, 7, 8, 4};
        int max = getMax(() -> {
            int rtn = arr[0];
            for (int i : arr) {
                if (i > rtn) {
                    rtn = i;
                }
            }
            return rtn;
        });


        System.out.println("Supplier数组最大值:" + max);


    }
}
